/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package GUI.Components;

import Tools.CMDThreadGUI;
import Tools.TModel;
import java.awt.Dimension;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.swing.*;

/**
 *
 * @author Ivan
 */
public abstract class ABrowserBuilder extends AComponentBuilder {

    protected final TModel model;
    protected String browserDirectory;
    protected final AObserverGUI observerGUI;
    protected JList browserList;
    protected DefaultListModel listModel = new DefaultListModel();
    protected JScrollPane browserScrollPane = new JScrollPane();
    protected int index = 0;
    private MouseListener action;

    public ABrowserBuilder(TModel model, AObserverGUI observerGUI) {
        this.observerGUI = observerGUI;
        this.model = model;

        browserList = new JList(listModel);
        browserList.setLayoutOrientation(JList.VERTICAL);

        browserScrollPane.setViewportView(browserList);
        browserScrollPane.setPreferredSize(new Dimension(observerGUI.getSize().width/2 - 50,observerGUI.getSize().height - observerGUI.getSize().height/2  ));

    }

    @Override
    public JComponent buildComponent() throws Exception {
        browserList.addMouseListener(action);
        return browserScrollPane;
    }

    protected void setAction(MouseListener action) {
        this.action = action;
    }

    public String getBrowserDirectory() {
        return browserDirectory;
    }

    public void setBrowserDirectory(String browserDirectory) {
        this.browserDirectory = browserDirectory;
    }

    public String getSelectedItem() {
        return (String) listModel.get(index);
    }

    public void hideBrowser() {
        browserScrollPane.setVisible(false);
        browserScrollPane.setEnabled(false);
    }

    public void showBrowser() {
        browserScrollPane.setVisible(true);
        browserScrollPane.setEnabled(true);
    }

    public boolean getVisibleState() {
        return browserScrollPane.isVisible();
    }
}
